$(document).ready(function(){
    var Instructor_id=0;
    $('.Search').click(function () {

        Search($($(this).attr('Link-id')).val()+'/');

    });

    $('.btn.btn-sm.btn-outline-secondary').click(function () {

        Instructor_id= this.id.replace('pj_1_','');

        $('#modal_dialog_1').addClass("show");

    });

    $('.btn.btn-sm.btn-outline-success').click(function () {

        Instructor_id= this.id.replace('pj_2_','');

        $('#modal_dialog_2').addClass("show");

    });

    $('.pj-2').click(function () {

        var PJType_id=this.id.replace('pj_','');

        new Ajax('./../../../train/pj/',{'PJType_id': PJType_id,'Instructor_id':Instructor_id},function (db) {
            $('#modal_dialog_2').removeClass("show");
        });

    });

    $('.pj-1').click(function () {

        var PJType_id=this.id.replace('pj_','');

        new Ajax('./../../../train/pj/',{'PJType_id': PJType_id,'Instructor_id':Instructor_id},function (db) {
            $('#modal_dialog_1').removeClass("show");
        });

    });

    $('.close').click(function () {
        $('#modal_dialog_2').removeClass("show");
        $('#modal_dialog_1').removeClass("show");
    });

    $('.Training-Btn').click(function () {
        new Ajax('./../../../train/',  {'Training':'yes','id':$(this).attr("training-id")},function (db) {
            if (db==null||db.error == 1) {
                alert('报名没成功!!!');
            } else {
                window.location.href = './../../../train/';
            }
        })
    });

    var Ajax=function(url,db,Callback){
        var Ajax = new window.XMLHttpRequest();
        Ajax.onreadystatechange = function (ev) {
            if (Ajax.readyState == 4 && Ajax.status == 200) {
                var db = JSON.parse(Ajax.responseText);
                Callback(db);
            }else{

            }
        }
        Ajax.open("post", url);
        Ajax.setRequestHeader('Accept','application/json, text/plain, */*');
        Ajax.setRequestHeader('Content-Type','application/json;charset=utf-8');
       var  paramet=JSON.stringify(db);
        Ajax.send(paramet);

    };

    $('.LoginBtn').click(function () {

        if(user.value!=""||pas.value!="") {
            new Ajax('./../../../train/Login.aspx',
                {'user':user.value,'pas':pas.value},function (db) {
                if (db==null||db.error == 1) {
                    alert('用户名或密码错误!!!');
                } else {
                    window.location.href = window.location.href;
                }
            });
        }else {
            alert("用户名或密码不能为空!");
        }
    });

    $('.Search-input').keypress(function(event){
        var keynum = (event.keyCode ? event.keyCode : event.which);
        if(keynum == '13'){
            Search($(this).val()+'/');
        }
    });

    var Search=function (value) {
        window.location.href=(window.location.protocol+'//'+window.location.host+'/Search/'+   value+'/');
    }
});